package com.htu.study.service.serviceImpl.user;

import com.htu.study.mapper.UserMapper;
import com.htu.study.pojo.User;
import com.htu.study.service.serviceImpl.user.utils.UserDetailsImpl;
import com.htu.study.service.user.InfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class InfoServiceImpl implements InfoService {
    @Autowired
    UserMapper userMapper;
    @Override
    public Map<String, String> getInfo() {
        UsernamePasswordAuthenticationToken authentication =
                (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();

        UserDetailsImpl loginUser = (UserDetailsImpl) authentication.getPrincipal();
        User user = loginUser.getUser();

        Map<String,String>map=new HashMap<>();
        map.put("user_id", String.valueOf(user.getUserId()));
        map.put("user_name",user.getUserName());
        map.put("user_photo",user.getUserPhoto());
        map.put("user_root",user.getUserRoot());
        return map;
    }
}
